﻿using System;
using System.ComponentModel.Composition;
using System.ComponentModel.DataAnnotations.Schema;
using System.Security.Permissions;

namespace PlutoStudio.EntityFramework.Test
{
    [Export] 
    class Program
    {
        [Import]
        public IRepository<Transactionflow> Repository { get; set; }

        static void Main(string[] args)
        {
            //System.Threading.Thread.CurrentPrincipal= new WindowsPrincipal(WindowsIdentity.GetCurrent());
            //DefaultContextInitialization.Initialization("ConnectionString");
            //MefContainer.Register<ProductRepository, IProductRepository>();
            //Entity<Transactionflow,long>.InitializeRepository();
            var context = MefContainer.GetService<IDbContext>();
            context.Preinitialize();
            //var result2 = context.SqlQuery<Transactionflow>("select * from c_transactionflow where date=20161102");
            ////foreach (var item in result)
            ////{
            ////    Console.WriteLine(item.Id);
            ////}
            //result2.ToList();
            //var resp = MefContainer.GetService<IRepository<Transactionflow, long>>();
            //var result = resp.Entities.Where(r => r.Date == 20161102);
            ////foreach (var item in result)
            ////{
            ////    Console.WriteLine(item.Key);
            ////}
            //result.ToList();
            //Console.WriteLine(MefContainer.Container);

            //var resp = MefContainer.GetService<Program>();
            //resp.Repository.Update(u => u.Id == 1, u => new Transactionflow { Amount = 10000M });
            //Console.WriteLine(resp.Repository.Entities.Where(t => t.CustomerID == 123).Max(t => t.Id));
            Test();
            //Console.WriteLine(result.Count());
        }
        [PrincipalPermission(SecurityAction.Demand, Authenticated = true)]
        public static void Test()
        {
            Console.WriteLine("Test");
        }
    }

    [Table("c_transactionflow")]
    public class Transactionflow : Entity<Transactionflow, long>
    {
        /// <summary>
        /// 用户ID
        /// </summary>
        public long CustomerID { get; set; }
        /// <summary>
        /// 金额
        /// </summary>
        public decimal? Amount { get; set; }
        /// <summary>
        /// 余额
        /// </summary>
        public decimal? Balance { get; set; }
        /// <summary>
        /// 账户流水号
        /// </summary>
        public string BillFlowNum { get; set; }
        /// <summary>
        /// 总账户流水号
        /// </summary>
        public string TotalBillFlowNum { get; set; }
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        [Column(TypeName ="binary")]
        public Decimal Remark { get; set; }
        /// <summary>
        /// 交易类型编码
        /// </summary>
        public string TransactionTypeCode { get; set; }
        /// <summary>
        /// 关联业务ID
        /// </summary>
        public long? BusinessID { get; set; }
        /// <summary>
        /// 关联业务表名
        /// </summary>
        public string BusinessTable { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public System.DateTime? CreateDate { get; set; }

        /// <summary>
        /// 流水日期
        /// </summary>
        public int? Date { get; set; }


    }




    //class TransactionflowRepository : RepositoryBase<Transactionflow, long>
    //{
    //}


}
